package com.atwei.mango.system.commen.utils;


import com.atwei.mango.system.securityHandler.SysAccount;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Classname LoginAccountUtil
 * @Description
 * @Date 2022/8/19 15:50
 * @Author liuwei
 */
public class LoginAccountUtil {
    public static SysAccount getAccount(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        System.out.println(authentication.getName());//用户名
//        System.out.println(authentication.getAuthorities());//拥有的所有角色
//        System.out.println(authentication.getPrincipal());//代表当前用户的信息,一般强转为User(SpringSecurity的User)对象
        return (SysAccount) authentication.getPrincipal();
    }
}
